<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
  <h1>微博详情页面</h1>
  <h2>{{weibo.nickname}}:{{weibo.content}}</h2>
  <p>发布于：{{weibo.created}}</p>
    <img v-for="url in weibo.urls.split(',')" width="200" :src="url" alt="">
    <hr>
    <div v-for="c in arr">
        <h4>
            {{c.nickname}}评论说：{{c.content}}
            <span style="float: right">发布于：{{c.created}}</span>
        </h4>
    </div>
    <input type="text" placeholder="评论内容。。" v-model="comment.content">
    <input type="button" value="评论" @click="insert()">
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!--引入axios和vue框架文件-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script>
    let v = new Vue({
        el:"body>div",
        data:{
            weibo:{urls:""},
            comment:{content:""},
            arr:[]
        },
        methods:{
            insert(){
                // alert(1);
                //查询当前weiboid
                v.comment.weiboId = v.weibo.id;
                alert(v.weibo.id);
                //发请求发布评论
                axios.post("/comment/insert",v.comment).then(function (response) {
                    if (response.data == 1) {
                        location.reload();//刷新页面
                    }else {
                        alert("请先登录");
                        location.href="/login.html";
                    }
                })

            }

        },
      created:function (){
            //发请求获取微博详情
          axios.get("/weibo/selectById"+location.search).then(function (response) {
            v.weibo = response.data;
          })
          //发请求获取所有的当前微博相关的评论
          axios.get("/comment/selectByWeiboId"+location.search).then(function (response) {
              v.arr = response.data;
              console.log(response.data);
          })

      }
    })
</script>

</body>
</html>